package com.ruoyi.system.controller.basic;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.PageInfo;
import com.ruoyi.system.utils.MyPageUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.db.basic.BasicMaterials;
import com.ruoyi.system.service.IBasicMaterialsService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 物资的类型Controller
 * 
 * @author sen
 * @date 2023-07-25
 */
@RestController
@RequestMapping("/basic/materials")
public class BasicMaterialsController extends BaseController
{
    @Autowired
    private IBasicMaterialsService basicMaterialsService;

    /**
     * 查询物资的类型列表
     */
    @PreAuthorize("@ss.hasPermi('basic:materials:list')")
    @GetMapping("/list")
    public PageInfo<BasicMaterials> list(BasicMaterials basicMaterials)
    {
        //startPage();
        List<BasicMaterials> list = basicMaterialsService.selectBasicMaterialsList(basicMaterials);
        return MyPageUtils.startPage(list);
    }

    /**
     * 导出物资的类型列表
     */
    @PreAuthorize("@ss.hasPermi('basic:materials:export')")
    @Log(title = "物资的类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasicMaterials basicMaterials)
    {
        List<BasicMaterials> list = basicMaterialsService.selectBasicMaterialsList(basicMaterials);
        ExcelUtil<BasicMaterials> util = new ExcelUtil<BasicMaterials>(BasicMaterials.class);
        util.exportExcel(response, list, "物资的类型数据");
    }

    /**
     * 获取物资的类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:materials:query')")
    @GetMapping(value = "/{materialId}")
    public AjaxResult getInfo(@PathVariable("materialId") Long materialId)
    {
        return success(basicMaterialsService.selectBasicMaterialsByMaterialId(materialId));
    }

    /**
     * 新增物资的类型
     */
    @PreAuthorize("@ss.hasPermi('basic:materials:add')")
    @Log(title = "物资的类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicMaterials basicMaterials)
    {
        return toAjax(basicMaterialsService.insertBasicMaterials(basicMaterials));
    }

    /**
     * 修改物资的类型
     */
    @PreAuthorize("@ss.hasPermi('basic:materials:edit')")
    @Log(title = "物资的类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicMaterials basicMaterials)
    {
        return toAjax(basicMaterialsService.updateBasicMaterials(basicMaterials));
    }

    /**
     * 删除物资的类型
     */
    @PreAuthorize("@ss.hasPermi('basic:materials:remove')")
    @Log(title = "物资的类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{materialIds}")
    public AjaxResult remove(@PathVariable Long[] materialIds)
    {
        return toAjax(basicMaterialsService.deleteBasicMaterialsByMaterialIds(materialIds));
    }
}
